package com.bn.commerce.pricing.calculators;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import com.bn.commerce.pricing.BNShippingCalculatorImpl;

import atg.commerce.order.ShippingGroup;
import atg.commerce.pricing.PricingException;
import atg.commerce.pricing.ShippingPricingCalculator;
import atg.commerce.pricing.ShippingPricingEngineImpl;
import atg.commerce.promotion.PromotionTools;
import atg.repository.RepositoryItem;
import atg.service.perfmonitor.PerfStackMismatchException;
import atg.service.perfmonitor.PerformanceMonitor;

public class BNShippingPricingEngineImpl extends ShippingPricingEngineImpl{

	public List<RepositoryItem> getAvailableMethodDetails(ShippingGroup pShipment, Collection pPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
			throws PricingException {

		vlogDebug("BNShippingPricingEngineImpl : getAvailableMethodDetails - Entry");
		String perfName = "getAvailableMethods";
		PerformanceMonitor.startOperation("BNShippingPricingEngineImpl", perfName);
		boolean perfCancelled = false;
		List<RepositoryItem> methodDetails = null;
		try {
			if (pShipment == null) {
				return null;
			}
			Locale locale = pLocale;
			if (locale == null) {
				locale = getDefaultLocale();
			}
			List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();

			if (getPreCalculators() != null) {
				int num = getPreCalculators().length;
				for (int c = 0; c < num; ++c) {
					ShippingPricingCalculator calc = getPreCalculators()[c];
					if (calc instanceof BNShippingCalculatorImpl) {
						vlogDebug(calc + " : It is instance of BNShippingCalculatorImpl..");
						methodDetails = ((BNShippingCalculatorImpl) calc).getAvailableMethodDetails(result, pShipment, pProfile, pLocale, pProfile, pExtraParameters);
					}
				}
			}

			vlogDebug("BNShippingPricingEngineImpl : getAvailableMethodDetails - Exit");
			return  methodDetails;
		} finally {
			try {
				if (!(perfCancelled)) {
					PerformanceMonitor.endOperation("BNShippingPricingEngineImpl", perfName);
					perfCancelled = true;
				}
			} catch (PerfStackMismatchException e) {
				if (isLoggingWarning())
					logWarning(e);
			}
		}
		}


}
